package org.apache.struts.edit.action;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.struts.edit.model.State;
import org.apache.struts.edit.service.EditService;
import org.apache.struts.edit.service.EditServiceInMemory;
import org.apache.struts.model.Person;

import com.opensymphony.xwork2.ActionSupport;

/**
 * Acts as a controller to handle actions related to editing a Person.
 * 
 * @author bruce phillips
 *
 */
public class EditAction extends ActionSupport {

    private static final long serialVersionUID = 1L;

    private EditService editService = new EditServiceInMemory();

    private Person personBean;

    private String[] sports = { "football", "baseball", "basketball" };

    private String[] genders = { "male", "female", "not sure" };

    private List<State> states;

    private String[] carModelsAvailable = { "Ford", "Chrysler", "Toyota", "Nissan", "Chevrolet" };

    public String execute() throws Exception {

	editService.savePerson(getPersonBean());

	return SUCCESS;

    }

    public String input() throws Exception {

	setPersonBean(editService.getPerson());

	return INPUT;
    }

    public Person getPersonBean() {

	return personBean;

    }

    public void setPersonBean(Person person) {

	personBean = person;

    }

    public List<String> getSports() {
	return Arrays.asList(sports);
    }

    public List<String> getGenders() {

	return Arrays.asList(genders);

    }

    public List<State> getStates() {

	states = new ArrayList<State>();
	states.add(new State("AZ", "Arizona"));
	states.add(new State("CA", "California"));
	states.add(new State("FL", "Florida"));
	states.add(new State("KS", "Kansas"));
	states.add(new State("NY", "New York"));
	states.add(new State("CH", "Chiapas"));

	return states;
    }

    public String[] getCarModelsAvailable() {
	return carModelsAvailable;
    }

}
